package the.formula.calculator;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TextView;

public class DegreesInPolygon extends Activity{

	private int numSides;
	private EditText sides;
	private String sSides;
	private TableLayout tl;
	private boolean answerAdded = false;
	private TextView tv;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.degrees_activity);
        tl = (TableLayout)findViewById(R.id.sidesLayout);
        tv = new TextView(this);
    }
    
    public void onClick(View v) {
    	switch(v.getId()) {
    	case R.id.DIPsolve:
    		solveForDegrees();
    		break;
    	}
    }

	private void solveForDegrees() {
		double answer = 0;
		sides = (EditText)findViewById(R.id.numSides);
		sSides = sides.getText().toString();
		numSides = Integer.parseInt(sSides);
		answer = 180 * (numSides - 2);
		
		if(answerAdded) {
			tl.removeView(tv);
		}
		tv.setText("Number of sides: " + answer);
		tl.addView(tv);
	}
        
        
}